/**
 * @fileOverview 资源管理器
 * 资源的存取
 */

var resource = {
    Event: {
        app: {
            start: "function() {console.log('appstart')}",
            stop: "function() {console.log('stop')}"
        }
    },
    Formula: {
        identity: "function(v){return v}"
    },
    Map: {
        default: {type:"Grid", width:10, height:20}
    }
};

module.exports = {
    /**
     * 获取资源
     * @param {String} uri
     * @returns {String}
     */
    get: function(uri) {
        if (!uri) {
            return resource;
        }
        var paths = uri.split('/'), res = resource;
        for (var i = 0; i < paths.length; i++) {
            res = res[paths[i]];
            if (res == null) {
                return null;
            }
        }
        return res;
    },
    /**
     * 存储资源
     * @param {String} uri
     * @param {String} key
     * @param {String} value
     * @returns {String}
     */
    set: function(uri, key, value) {
        if (!uri) {
            return false;
        }
        var paths = uri.split('/'), res = resource;
        for (var i = 0; i < paths.length; i++) {
            if (res[paths[i]] == null) {
                res[paths[i]] = {};
            }
            res = res[paths[i]];
        }
        res[key] = value;
    },
    /**
     * 持久化存储资源
     * @param {String} uri
     */
    save: function(uri) {

    },
    /**
     * 从存储器中加载资源
     * @param {String} uri
     */
    load: function(uri) {

    }
};